import axios from "axios";
class SQL{
    sql;
    //返回sql
    static getSql() {
        if (this.sql == null){
            this.sql =  new SQL();
            return this.sql;
        }
        else {
            return this.sql;
        }
    }

    //更新感染人数
    updateInfected(SchoolName,Infected){
        axios.post('/api/sqlApi/updateInfected',{
            SchoolName,Infected
            // eslint-disable-next-line no-unused-vars
        }).then(res=>{
            alert('更改成功！');
            //console.log(res);
        })
    }

    //查询感染人数
    async selectInfected(SchoolName){
        let infected
        await axios.post('/api/sqlApi/selectInfected',{
            SchoolName
        }).then(res=>{
            //console.log(res);
            let data = res.data[0];
            infected = data.Infected;
        })
        return infected
    }

    //更新剩余物资
    updateAllMaterial(Name, Num){
        axios.post('/api/sqlApi/updateAllMaterial',{
            Name,Num
            // eslint-disable-next-line no-unused-vars
        }).then(res=>{
            alert('更改成功！');
            //console.log(res);
        })
    }

    //查询剩余物资
    async selectAllMaterial(Name){
        let Num
        await axios.post('/api/sqlApi/selectAllMaterial',{
            Name
        }).then(res=>{
            //console.log(res);
            let data = res.data[0];
            Num = data.Num;
        })
        return Num
    }

    //更新物资分配
    updateMaterial(SchName, MaName, Num){
        axios.post('/api/sqlApi/updateMaterial',{
            SchName, MaName, Num
            // eslint-disable-next-line no-unused-vars
        }).then(res=>{
           //console.log(res);
        })
        Num = -Num;
        let Name = MaName
        axios.post('/api/sqlApi/updateAllMaterial',{
            Name,Num
            // eslint-disable-next-line no-unused-vars
        }).then(res=>{
            alert('更改成功！');
            //console.log(res);
        })
    }

    //查询物资分配
    async selectMaterial(SchName, MaName){
        let Num
        await axios.post('/api/sqlApi/selectMaterial',{
            SchName,MaName
        }).then(res=>{
            //console.log(res);
            let data = res.data[0];
            Num = data.Num;
        })
        return Num
    }
}

export default SQL